/* $Id: AdminClientPersonReviewDelegateImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.delegate.provider;


import ae.pcfc.etks.online.common.delegate.AdminClientPersonReviewDelegate;
import ae.pcfc.etks.online.common.exception.AdminWorkflowException;
import ae.pcfc.etks.online.common.facade.AdminClientPersonReviewFacade;
import ae.pcfc.etks.online.common.vo.AdminApprovalVO;
import ae.pcfc.etks.online.common.vo.ClientPersonVO;
import ae.pcfc.etks.online.wf.service.client.provider.ClientPersonAdminWFImpl;
import ae.pcfc.etks.online.wf.service.client.vo.ClientAdminCompleteStepVO;



public class AdminClientPersonReviewDelegateImpl extends BaseDelegateImpl implements AdminClientPersonReviewDelegate{

	/*
	 * Here we coordinate between the Facade service which handles DB entities
	 * and the WF both will be looked up with service locator normally we will
	 * have 1-1 relationship between the delegate and the facade and 1-1
	 * relationship between the delegate and the WF service which means for
	 * CompanyRegistrationDelegate there will be ClientRegistrationFacade &
	 * CompanyRegistrationWF validations that related to DB vs WF are maintained
	 * here ie user cannot issue a new request while he already have a request
	 * in the wf Exception are translated in to business exception
	 */
	public AdminClientPersonReviewDelegateImpl(){
		
	}
	
	/**
	 * getClientPersonByApplicationId
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.AdminClientPersonReviewDelegate#getClientPersonByApplicationId(java.lang.Long)
	 * 
	 */
	public ClientPersonVO getClientPersonByApplicationId(Long applicationId) {
		
		return serviceLocator.getFacadeService(AdminClientPersonReviewFacade.class).getClientPersonByApplicationId(applicationId);		
	
	}

	/**
	 * reviewRegisterClientPerson
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.AdminClientPersonReviewDelegate#reviewRegisterClientPerson(ae.pcfc.etks.online.common.vo.AdminApprovalVO, ae.pcfc.etks.online.common.vo.ClientPersonVO)
	 * 
	 */
	public void reviewRegisterClientPerson(AdminApprovalVO adminApprovalVO, ClientPersonVO clientPersonVO) {
		 
		//serviceLocator.getFacadeService(AdminClientPersonReviewFacade.class).reviewRegisterClientPerson(adminApprovalVO, clientPersonVO);
    	AdminClientPersonReviewFacade adminClientPersonReviewFacade = serviceLocator.getFacadeService(AdminClientPersonReviewFacade.class);
    	ClientAdminCompleteStepVO completeStepVO = adminClientPersonReviewFacade.reviewRegisterClientPerson(adminApprovalVO, clientPersonVO);
 	    try{
	    	ClientPersonAdminWFImpl clientPersonAdminWFImpl =serviceLocator.getWorkflowService(ClientPersonAdminWFImpl.class);
	    	clientPersonAdminWFImpl.completeClientAdminWFStep(completeStepVO);
 	    }catch(Throwable t){
 	    	adminClientPersonReviewFacade.undoReviewRegisterClientPerson(adminApprovalVO, clientPersonVO);
 	    	throw new AdminWorkflowException(t);
 	    }
	}

}
